<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: jasny-bootstrap-css" />
    <th:block th:include="include :: header('修改相册')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-album-edit" th:object="${bizAlbum}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">相册标题：</label>
                <div class="col-sm-8">
                    <input name="title" th:field="*{title}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <div class="fileinput fileinput-new" data-provides="fileinput" style="width: 100%;">
                    <div class="fileinput-new thumbnail" style="width: 80%; height: 200px; margin-left: 10%;">
                        <img th:src="*{titlePic}">
                    </div>
                    <div class="fileinput-preview fileinput-exists thumbnail" style="width: 80%; height: 200px; margin-left: 10%;"></div>
                    <div style="float: right; margin-right: 10%;">
                        <span class="btn btn-white btn-file">
                            <span class="fileinput-new">选择图片</span>
                            <span class="fileinput-exists">更改</span>
                            <input id="img-input" type="file">
                        </span>
                        <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        <button id="save-img" type="button" class="btn btn-outline btn-primary">保存</button>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">封面图片：</label>
                <div class="col-sm-8">
                    <input id="img-path" name="titlePic" th:field="*{titlePic}" class="form-control" type="text" required readonly>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:src="@{/ruoyi/js/utils.js}"></script>
    <script type="text/javascript">
        var prefix = ctx + "system/album";
        $("#form-album-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-album-edit').serialize());
            }
        }

        var imgChange = false;
        $("#img-input").on("change.bs.fileinput", function () {
            imgChange = true;
        });
        
        $("#save-img").click(function () {
            if (!imgChange) {
                $.modal.msgError('banner没有改变');
                return;
            }
            var file = $('#img-input')[0].files[0];
            if (file == null) {
                $.modal.msgError('请选择要上传的banner图片');
                return;
            }
            upload(file, function (res) {
                $("#img-path").val(res.url);
                $.modal.msgSuccess("保存成功");
            });
        });
    </script>
</body>
</html>